package service

import (
	"github.com/gin-gonic/gin"
	"zk2/product-guard/internal/dto"
	"zk2/product-guard/internal/model"
	"zk2/product-guard/response"
)

func Create(c *gin.Context) {

	var shop model.Shop
	err := c.ShouldBind(&shop)
	if err != nil {
		response.Error(c, "参数错误")
		return
	}

	shop = model.Shop{
		Name:  shop.Name,
		Price: shop.Price,
		Num:   shop.Num,
	}
	if shop.Name == "" || shop.Price == 0 || shop.Num == 0 {
		response.Error(c, "参数不能为空")
		return
	}
	err = dto.CreateShop(&shop)
	if err != nil {
		response.Error(c, "添加失败")
		return
	}
	response.Success(c, "添加成功", shop.ID)
}
